<template>
  <div>
    <div class="header">
      <h3>{{filmdetial.name}}</h3>
      <ul>
        <li
          v-for="(i,index) in times" :style="{color:i.cinemaList==idforcolor?'#ff5f16':''}"
          :key="index"
          @click="touchme(i)"
        >{{dateday(i.showDate)}}</li>
      </ul>
    </div>
    <usecinemalist />
  </div>
</template>
<script>
import { orderbyfilm, orderbytime,getway } from "@/api";
import usecinemalist from "@/components/cinemalist.vue";
export default {
  components: { usecinemalist },
  computed: {
    city() {
      return this.$store.state.city.id;
    }
  },
  data() {
    return {
      filmdetial: "",
      times: "",
      timenow: "",
      idforcolor:""
    };
  },
  methods: {
    dateday(i) {
      //计算时间
      var myDate = new Date();
      myDate.setTime(1000 * i);
      var mytime = `${myDate.getMonth() + 1}月${myDate.getDate()}日`;
      return mytime;
    },
    citycinema(id) {
      //获取城市的影院
      this.$store.dispatch("changecinema", id);
    },
    touchme(i) {
      //滑动点击时间
      getway(this.city).then(resp => {
        resp.data.data.cinemas = resp.data.data.cinemas.filter(k => {
          return i.cinemaList.indexOf(k.cinemaId) > -1;
        });
        this.idforcolor = i.cinemaList
        this.$store.commit("changes", resp);
        console.log(i.showDate)
        this.$store.commit('changesendfilm',{n:this.filmdetial.filmId,t:i.showDate})
      });
    }
  },
    created() {
        Promise.all([
      orderbyfilm(this.$route.params.id).then((
        res //获取影院
      ) => {
        this.filmdetial = res.data.data.film;
      }),
      orderbytime(this.city, this.$route.params.id).then(resp => {
        //获取上映时间和影院的关联表
        var a = resp.data.data.showCinemas
        this.times = a.sort((e,f)=>{            //时间排序
            return e.showDate-f.showDate
        })
      })]
        ).then(()=>{this.touchme(this.times[0])})    //首次加载第一个
    }
};
</script>
<style  scoped>
.header {
  width: 100%;
  position: fixed;
  top: 0;
  z-index: 99;
  background: white;
}
h3 {
  height: 1rem;
  text-align: center;
  line-height: 1rem;
  width: 100%;
  font-size: 0.3rem;
}
ul {
  width: auto;
  height: 1rem;
  overflow-x: scroll;
  white-space: nowrap;
}
ul li {
  display: inline-block;
  line-height: 1rem;
  height: 1rem;
  white-space: nowrap;
  text-align: center;
  padding: 0 0.2rem;
  font-size: 0.3rem;
}
</style>
<style>
.citys {
  position: relative !important;
  padding-top: 1rem;
}
.body {
  padding-top: 1rem !important;
}
</style>